<?php $this->load->module('mobile/index/header', $common);?>
<div class="content">
    <?php if($cat_name){?>
    <div class="fitler-m">
        <ul>
            <li class="filter-btn" style="background:#fff"><a href="javascript:;"><?php echo $cat_name?><i></i></a></li>
<!--            <li class="filter-btn"><a href="#">行程天数<i></i></a></li>-->
<!--            <li class="filter-btn"><a href="--><?php //echo site_url('mobile/line/filter/?cat_id='.$_GET['cat_id']);?><!--">筛选<i></i></a></li>-->
            <?php if($fcat_name || $pricedis){?>
            <li style="background:none;border:0;width:50%">
            <div class="f-selected">
                <a onclick="clear_cat()"><?php echo $fcat_name;?></a>
                <a onclick="clear_price()"><?php echo $pricedis['name'];?></a>
            </div>
            </li>
            <?php }?>
        </ul>
    </div>
    <?php }?>
    <style type="text/css">
        .f-selected{
            height:100%;line-height:40px;background:linear-gradient(#DADADA,#DCDCDC);
            color:#646464!important;
            text-align: center;
        }
        div.f-selected>a{
            color:#646464!important;
            display:inline!important;
        }
        .filter-btn, .fitler-m{
            background:#F0F0F0;
        }

        .filter-b{
            background:rgb(248, 248, 248);
            position:absolute;
            width:100%;
            box-shadow:0 1px 2px #cacaca;
            display:none;
        }

        .f-nav{
            float:left;
            width:50%;
            top:0;
            left:0;
            z-index:3;
            background:#fff;
            border-right:#F0F0F0 1px solid;
        }

        .f-nav li{
            float:left;
            width:100%;
            height:50px;
            line-height:50px;
            border-bottom:1px solid #F0F0F0;
            padding-left:10px;
        }

        .f-nav li a{
            display:block;
            color:#888;
        }
        .f-nav li.f-on a{
            color:#308900;
        }

        .f-content{
            float:right;
            width:50%;
            height:100%;
            overflow:hidden;
            color:#888;
        }
        .f-content li{
            height:40px;
            line-height:40px;
            border-bottom:1px solid #F0F0F0;
            padding-left:20px;
        }
        .f-content a{
            color:#888;
        }
    </style>
    <?php $srch = array(URLPRE,'preview=1','touchtpl=default','touchtpl=weixin', '&','?');?>
    <div class="filter-b">
        <div class="f-nav">
            <ul>
                <?php foreach($select_categorys as $k => $v){?>
                    <li><a href="javascript:;" onclick="showsub(this, '<?php echo @str_replace($srch,'', $v['link_url']);?>')"><?php echo @$v['name'];?></a></li>
                <?php }?>
            </ul>
        </div>
        <?php foreach(array_values($select_categorys) as $k => $v){?>
        <div class="f-content" id="<?php echo @str_replace($srch,'', $v['link_url'])?>" <?php if($k>0){?>style="display:none;" <?php }?>>
            <ul>
                <?php foreach($v['child'] as $child):?>
                    <li><a href="javascript:;" onclick="append_filter('<?php
                        echo str_replace($srch,'', $child['link_url']);
                        ?>');"><?php echo $child['name'];?> </a></li>
                <?php endforeach;?>
            </ul>
        </div>
        <?php }?>
    </div>

    <div class="micro-line-list-box" id="list">

        <?php if($datalist){foreach ($datalist as $v) { ?>
        <dl class="line-list1">
            <dt><a href="<?php echo $v['link'];?>" title="<?php echo $v['line_name'];?>"> <img class="lazy" src="<?php echo URLPRE;?>static/public/images/nophoto.jpg" onerror="this.error=null;this.src='<?php echo URLPRE;?>static/public/images/nophoto.jpg'" _src="<?php echo $v['file_url'];?>" alt="<?php echo $v['line_name'];?>"></a></dt>
            <dd>
                <a href="<?php echo $v['link'];?>" title="<?php echo $v['line_name'];?>">
                    <p class="t"> <?php echo $v['line_name'];?></p>
                    <p class="p"> <span><?php echo $v['low_price'];?></span><?php echo $v['sold']?>人去过</p>
                </a>
            </dd>
        </dl>
        <?php }}else{?>
        <dl class="line-list1">
           <dd style="width:100%;text-align: center"><a style="width:100%;text-align: center" href="tel:<?php echo $site_service_phone;?>">暂无线路，点击电询</a></dd>
        </dl>
        <?php }?>
    </div>
    <?php if($datalist){ ?><a href="javascript:;" class="btn-grey btn">加载更多</a>
    <?php }?>
</div>
<?php $this->load->module('mobile/index/footer', $common);?>
<script type="text/javascript">
    var BASEURL = '<?php echo URLPRE;?>';
    $(function(){
        var slid = $("#sliderimg").slider({
            loop: true
        });
        var page = <?php echo $page+1;?>;
        var keyword = '<?php echo $keyword?>';
        var cat_id = '<?php echo $cat_id ?>';
        var url = '<?php echo site_url('mobile/line/index');?>';
        var cat = localStorage.getItem('cat<?php echo $cat_id ?>'), price = localStorage.getItem('price<?php echo $cat_id ?>');
        if(cat == null){
        }
        cat = '<?PHP echo $_GET['cat']?>';
        price = '<?PHP echo $_GET['price']?>';
        if(price == null){
        }

        $('.btn-grey').click(function(){
            var $this = $(this);
            $this.text('加载中...');
            $.get(url+(url.indexOf('?')!=-1 ?'&':'/?')+'isajax=1&cat_id='+cat_id+'<?php echo "&city=$_GET[city]&dcity=$_GET[dcity]&day=$_G[day]&mark=$_GET[mark]"?>&keyword='+keyword+'&cat='+cat+'&price='+price+'&page='+page, function(data){
                if(data.length>0){
                    var html = '';
                    for(var i =0; i<data.length; i++){
                        var l = data[i];

                        html += '<dl class="line-list1">' +
                        '<dt><a href="'+ l.link+'" title="'+ l.line_name+'">' +
                        '<img class="lazy" src="'+BASEURL+'static/public/images/nophoto.jpg" onerror="this.error=null;this.src=\''+BASEURL+'static/public/images/nophoto.jpg\'" _src="'+ l.file_url +'" alt="'+ l.line_name+'"></a></dt><dd>' +
                        '<a href="'+ l.link+'" title="'+ l.line_name+'"><p class="t"> '+ l.line_name+'</p>' +
                        '<p class="p"> <span>'+ l.low_price+'</span>'+ l.sold+'人去过</p></a>' +
                        '</dd>'+
                        '</dl>';
                    }
                    $('#list').append(html);
                    page ++;
                    $this.text('加载更多');
                    lazyLoad.init();
                }else{

                    $.dialog({
                        style:'tip',
                        width:200,
                        closeTime:1000,
                        content: '<p style="text-align: center">没有更多了</p>'
                    }).open();
                    $this.text('没有更多了');
                }
            },'json');
        });
        $('.search_btn').click(function () {
            keyword = $('#search_name').val();
            if(keyword.length> 0){
                keyword = encodeURIComponent(keyword);
                window.location.href = url+(url.indexOf("?") > -1 ? "&" : "?")+'cat_id=<?php echo $cat_id?>&keyword='+keyword;
            }
        });
        $('.filter-btn').click(function(){
            $(this).siblings().css('background','#F0F0F0');
            $(this).css('background','#fff');
            $('.filter-b').toggle();
        });
    });
    function showsub(obj, id){
        $(obj).parent().addClass('f-on').siblings('li').removeClass('f-on');
        $('#'+id).show();
        $('#'+id).siblings('.f-content').hide();
    }

    function append_filter(id){
        var BASEURL = '<?php echo URLPRE?>';
        if(id.indexOf('-') == '-1'){ /*cat*/
            localStorage.setItem('cat<?php echo $cat_id ?>', id);
        }else if(id.indexOf('-')>-1){
            localStorage.setItem('price<?php echo $cat_id ?>', id);
        }
        var cat = localStorage.getItem('cat<?php echo $cat_id ?>'), price = localStorage.getItem('price<?php echo $cat_id ?>');
        if(cat == null){
            cat = '';
        }
        if(price == null){
            price = '';
        }
        window.location.href = BASEURL+'mobile/line/?cat_id=<?php echo $cat_id?>&cat='+ cat + '&price='+price;
    }
    function clear_cat(){
        var cat = localStorage.getItem('cat<?php echo $cat_id ?>'), price = localStorage.getItem('price<?php echo $cat_id ?>');
        if(cat == null){
            cat = '';
        }
        if(price == null){
            price = '';
        }
        localStorage.removeItem('cat<?php echo $cat_id ?>');
        window.location.href = BASEURL+'mobile/line/?cat_id=<?php echo $cat_id?>&price='+price;
    }
    function clear_price(){
        var cat = localStorage.getItem('cat<?php echo $cat_id ?>'), price = localStorage.getItem('price<?php echo $cat_id ?>');
        if(cat == null){
            cat = '';
        }
        if(price == null){
            price = '';
        }
        localStorage.removeItem('price<?php echo $cat_id ?>');
        window.location.href = BASEURL+'mobile/line/?cat_id=<?php echo $cat_id?>&cat='+ cat;
    }
</script>